//void, ObjList objs,point pt, Obj obj, bool bReplace, bool bModifier, int player

Unit u;
Obj cat;
ObjList builders;
int i;
int maxunits;
IntArray race_num;
int race;
int max;
int rn;
int p;

maxunits = GetConst("CatapultMaxUnits");

cat.Clear();
objs.ClearDead();
builders = objs.FilterClosest(pt,maxunits);
//if(builders.count < minunits) return;

for (i = builders.count - 1; i >= 0; i -= 1) {
	race_num[builders[i].race] += 1;
}

max = -1;
for (i = 0; i < race_num.size; i += 1) {
	if (max < race_num[i]) {
		race = i;
		max = race_num[i];
	}
}
if(race == 2)
	race = 6;

p = builders[0].AsUnit().player;
cat = PlaceCatapult(pt.x, pt.y, p, race);
if(cat.IsValid)
	for(i = 0; i < builders.count; i += 1)
	{
		u = builders[i].AsUnit();
		u.SetCommand("build_catapult", cat);
		u.Deselect();
	}
	